SY吃喝玩樂

貼文
關於
建立屬於您的粉絲團、社團、部落格、官方網站、討論區、發佈平台
立即創建
分享 推播通知
目前身份: 訪客

http://note.tc.edu.tw/868.html

/ pattern /
什麼都不加,就是貪婪

/ pattern /U
就是非貪婪


什麼是貪婪?
就是全部都要抓

什麼是非貪婪?
就是只抓1次


$str= "A running dog rams a walking pig.";

// Greedy matches ... default matches 貪婪比對,取出最大字串
$IsMatch= preg_match('/(.*)<\/b>/', $str, $match);
if( $IsMatch ){
print $match[1] . "\n" ;
}

// Nongreedy matches, use U modifier 非貪比對,取出最頭及最小字串
$IsMatch= preg_match('/(.*)<\/b>/U', $str, $match);
if( $IsMatch ){
print $match[1] . "\n" ;
}






人氣 1114
SY吃喝玩樂 發表在 留言 (0) 人氣 (1114)
【Regular Expression】
分享給朋友
網址

想對外分享這則貼文嗎?運用網址更方便呦~

本月熱門貼文
台灣 一週天氣
OnceHit© 2024
載入中...